package com.qfedu.controller;

import com.qfedu.pojo.Order;
import com.qfedu.pojo.OrderCount;
import com.qfedu.service.OrderService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("order")
public class OrderController {
    @Resource
    private OrderService orderService;


@RequestMapping("selectOne")
public Order selectOne(Integer id) {
    return (Order) this.orderService.queryById(id);
}
    @RequestMapping("selectAll")
    public ModelAndView selectAll( ) {
        List<OrderCount> orderItems = this.orderService.selectOrders();
        return  new ModelAndView("/admin/AllOrder","orders",orderItems);
    }



    @RequestMapping("/selectOrdersByUser")
    @ResponseBody
    public List<OrderCount> selectOrdersByUser(@RequestBody Map map) {
        //ModelAndView md=new ModelAndView();

        List<OrderCount> orderCounts = orderService.selectOrdersByUser(Integer.parseInt(map.get("uid").toString()));
        System.out.println(orderCounts);
        //md.addObject("order",orderCounts);
        //md.setViewName("/admin/UserOrder");
        return orderCounts;
    }

    @RequestMapping("/del")
    @ResponseBody
    public String  delById(Integer id) {
        orderService.deleteById(id);
 return "222";
    }


}
